package com.inei.view;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import com.inei.R;
import com.inei.controller.RespuestaCensoController;
import com.inei.model.entity.RespuestaCenso;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TimePicker;
import android.widget.Toast;

public class Evaluacion_II_Activity extends Activity {

	// variables de componentes
	private Spinner sp11, sp12, sp21, sp22, sp31, sp32, sp41, sp42, sp51, sp52,
			sp61, sp62, sp71, sp72, sp81, sp82, sp91, sp92, sp101, sp102,
			sp111, sp112;
	private EditText et13, eti13, ett13, et14, et23, eti23, ett23, et24, et33,
			eti33, ett33, et34, et43, eti43, ett43, et44, et53, eti53, ett53,
			et54, et63, eti63, ett63, et64, et73, eti73, ett73, et74, et83,
			eti83, ett83, et84, et93, eti93, ett93, et94, et103, eti103,
			ett103, et104, et113, eti113, ett113, et114, etFuente11,
			etFuente12, etFuente21, etFuente22, etFuente31, etFuente32,
			etFuente41, etFuente42, etFuente51, etFuente52, etFuente61,
			etFuente62, etFuente71, etFuente72, etFuente81, etFuente82,
			etFuente91, etFuente92, etFuente101, etFuente102, etFuente111,
			etFuente112;

	// variables
	private RespuestaCensoController con;
	private RespuestaCenso obj;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.evaluacion_ii);

		con = new RespuestaCensoController(Evaluacion_II_Activity.this);

		IniciarComponentes();

		// CargarDatos();

		sp11.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp11, etFuente11, obj.getC3_1B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp12.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp12, etFuente12, obj.getC3_2B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp21.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp21, etFuente21, obj.getC4_1B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp22.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp22, etFuente22, obj.getC4_2B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp31.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp31, etFuente31, obj.getC5_1B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp32.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp32, etFuente32, obj.getC5_2B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp41.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp41, etFuente41, obj.getC6_1B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp42.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp42, etFuente42, obj.getC6_2B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp51.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp51, etFuente51, obj.getC7_1B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp52.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp52, etFuente52, obj.getC7_2B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp61.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp61, etFuente61, obj.getC7_21B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp62.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp62, etFuente62, obj.getC7_22B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp71.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp71, etFuente71, obj.getC7_31B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp72.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp72, etFuente72, obj.getC7_32B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp81.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp81, etFuente81, obj.getC8_1B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp82.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp82, etFuente82, obj.getC8_2B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp91.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp91, etFuente91, obj.getC9_1B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp92.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp92, etFuente92, obj.getC9_2B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp101.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp101, etFuente101, obj.getC10_1B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp102.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp102, etFuente102, obj.getC10_2B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp111.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarFuente(sp111, etFuente111, obj.getC11_1B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		sp112.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> adapter, View v, int pos,
					long arg3) {
				MostrarAcciones(sp112, etFuente112, obj.getC11_2B());
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		eti13.setFocusable(false);
		eti13.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett13.setFocusable(false);
		ett13.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		eti23.setFocusable(false);
		eti23.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett23.setFocusable(false);
		ett23.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		eti33.setFocusable(false);
		eti33.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett33.setFocusable(false);
		ett33.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		eti43.setFocusable(false);
		eti43.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett43.setFocusable(false);
		ett43.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		eti53.setFocusable(false);
		eti53.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett53.setFocusable(false);
		ett53.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		eti63.setFocusable(false);
		eti63.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett63.setFocusable(false);
		ett63.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		eti73.setFocusable(false);
		eti73.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett73.setFocusable(false);
		ett73.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		eti83.setFocusable(false);
		eti83.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett83.setFocusable(false);
		ett83.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		eti93.setFocusable(false);
		eti93.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett93.setFocusable(false);
		ett93.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		eti103.setFocusable(false);
		eti103.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett103.setFocusable(false);
		ett103.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		eti113.setFocusable(false);
		eti113.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});

		ett113.setFocusable(false);
		ett113.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				EditText et = (EditText) v;
				AbrirTime(et.getText().toString(), et, 0, "");
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu_evaluacion_ii, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) {
		case R.id.mnGuardar:
			GuardarDatos();
			break;
		case R.id.mnSalir:
			finish();
			break;
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onBackPressed() {
		Intent ir_evaluacion_i = new Intent(this, Evaluacion_I_Activity.class);
		ir_evaluacion_i.putExtras(getIntent().getExtras());
		startActivity(ir_evaluacion_i);
		finish();

		super.onBackPressed();
	}

	private void IniciarComponentes() {
		sp11 = (Spinner) findViewById(R.id.sp11);
		sp12 = (Spinner) findViewById(R.id.sp12);
		sp21 = (Spinner) findViewById(R.id.sp21);
		sp22 = (Spinner) findViewById(R.id.sp22);
		sp31 = (Spinner) findViewById(R.id.sp31);
		sp32 = (Spinner) findViewById(R.id.sp32);
		sp41 = (Spinner) findViewById(R.id.sp41);
		sp42 = (Spinner) findViewById(R.id.sp42);
		sp51 = (Spinner) findViewById(R.id.sp51);
		sp52 = (Spinner) findViewById(R.id.sp52);
		sp61 = (Spinner) findViewById(R.id.sp61);
		sp62 = (Spinner) findViewById(R.id.sp62);
		sp71 = (Spinner) findViewById(R.id.sp71);
		sp72 = (Spinner) findViewById(R.id.sp72);
		sp81 = (Spinner) findViewById(R.id.sp81);
		sp82 = (Spinner) findViewById(R.id.sp82);
		sp91 = (Spinner) findViewById(R.id.sp91);
		sp92 = (Spinner) findViewById(R.id.sp92);
		sp101 = (Spinner) findViewById(R.id.sp101);
		sp102 = (Spinner) findViewById(R.id.sp102);
		sp111 = (Spinner) findViewById(R.id.sp111);
		sp112 = (Spinner) findViewById(R.id.sp112);

		et13 = (EditText) findViewById(R.id.et13);
		et23 = (EditText) findViewById(R.id.et23);
		et33 = (EditText) findViewById(R.id.et33);
		et43 = (EditText) findViewById(R.id.et43);
		et53 = (EditText) findViewById(R.id.et53);
		et63 = (EditText) findViewById(R.id.et63);
		et73 = (EditText) findViewById(R.id.et73);
		et83 = (EditText) findViewById(R.id.et83);
		et93 = (EditText) findViewById(R.id.et93);
		et103 = (EditText) findViewById(R.id.et103);
		et113 = (EditText) findViewById(R.id.et113);

		eti13 = (EditText) findViewById(R.id.eti13);
		eti23 = (EditText) findViewById(R.id.eti23);
		eti33 = (EditText) findViewById(R.id.eti33);
		eti43 = (EditText) findViewById(R.id.eti43);
		eti53 = (EditText) findViewById(R.id.eti53);
		eti63 = (EditText) findViewById(R.id.eti63);
		eti73 = (EditText) findViewById(R.id.eti73);
		eti83 = (EditText) findViewById(R.id.eti83);
		eti93 = (EditText) findViewById(R.id.eti93);
		eti103 = (EditText) findViewById(R.id.eti103);
		eti113 = (EditText) findViewById(R.id.eti113);

		ett13 = (EditText) findViewById(R.id.ett13);
		ett23 = (EditText) findViewById(R.id.ett23);
		ett33 = (EditText) findViewById(R.id.ett33);
		ett43 = (EditText) findViewById(R.id.ett43);
		ett53 = (EditText) findViewById(R.id.ett53);
		ett63 = (EditText) findViewById(R.id.ett63);
		ett73 = (EditText) findViewById(R.id.ett73);
		ett83 = (EditText) findViewById(R.id.ett83);
		ett93 = (EditText) findViewById(R.id.ett93);
		ett103 = (EditText) findViewById(R.id.ett103);
		ett113 = (EditText) findViewById(R.id.ett113);

		et14 = (EditText) findViewById(R.id.et14);
		et24 = (EditText) findViewById(R.id.et24);
		et34 = (EditText) findViewById(R.id.et34);
		et44 = (EditText) findViewById(R.id.et44);
		et54 = (EditText) findViewById(R.id.et54);
		et64 = (EditText) findViewById(R.id.et64);
		et74 = (EditText) findViewById(R.id.et74);
		et84 = (EditText) findViewById(R.id.et84);
		et94 = (EditText) findViewById(R.id.et94);
		et104 = (EditText) findViewById(R.id.et104);
		et114 = (EditText) findViewById(R.id.et114);

		etFuente11 = (EditText) findViewById(R.id.etFuente11);
		etFuente12 = (EditText) findViewById(R.id.etFuente12);
		etFuente21 = (EditText) findViewById(R.id.etFuente21);
		etFuente22 = (EditText) findViewById(R.id.etFuente22);
		etFuente31 = (EditText) findViewById(R.id.etFuente31);
		etFuente32 = (EditText) findViewById(R.id.etFuente32);
		etFuente41 = (EditText) findViewById(R.id.etFuente41);
		etFuente42 = (EditText) findViewById(R.id.etFuente42);
		etFuente51 = (EditText) findViewById(R.id.etFuente51);
		etFuente52 = (EditText) findViewById(R.id.etFuente52);
		etFuente61 = (EditText) findViewById(R.id.etFuente61);
		etFuente62 = (EditText) findViewById(R.id.etFuente62);
		etFuente71 = (EditText) findViewById(R.id.etFuente71);
		etFuente72 = (EditText) findViewById(R.id.etFuente72);
		etFuente81 = (EditText) findViewById(R.id.etFuente81);
		etFuente82 = (EditText) findViewById(R.id.etFuente82);
		etFuente91 = (EditText) findViewById(R.id.etFuente91);
		etFuente92 = (EditText) findViewById(R.id.etFuente92);
		etFuente101 = (EditText) findViewById(R.id.etFuente101);
		etFuente102 = (EditText) findViewById(R.id.etFuente102);
		etFuente111 = (EditText) findViewById(R.id.etFuente111);
		etFuente112 = (EditText) findViewById(R.id.etFuente112);

		CargarDatos();
	}

	private void CargarDatos() {
		obj = new RespuestaCenso();
		obj.setMarco_id(getIntent().getExtras().getInt("marco_id"));
		obj.setRespuesta_id(getIntent().getExtras().getInt("respuesta_id"));
		obj.setFormato_id(getIntent().getExtras().getInt("formato_id"));
		obj = con.RespuestaCensoBuscar(obj);

		if (obj != null) {
			if (obj.getC3_1A() != null) {
				sp11.setSelection(Integer.parseInt(obj.getC3_1A()));
			}
			if (obj.getC3_2A() != null) {
				sp12.setSelection(Integer.parseInt(obj.getC3_2A()));
			}
			et13.setText(obj.getC3_3M() + "");
			if (obj.getC3_3IH() != null && obj.getC3_3IM() != null) {
				eti13.setText(obj.getC3_3IH() + ":" + obj.getC3_3IM());
			}
			if (obj.getC3_3FH() != null && obj.getC3_3FM() != null) {
				ett13.setText(obj.getC3_3FH() + ":" + obj.getC3_3FM());
			}
			et14.setText(obj.getC3_OB());

			if (obj.getC4_1A() != null) {
				sp21.setSelection(Integer.parseInt(obj.getC4_1A()));
			}
			if (obj.getC4_2A() != null) {
				sp22.setSelection(Integer.parseInt(obj.getC4_2A()));
			}
			et23.setText(obj.getC4_3M() + "");
			if (obj.getC4_3IH() != null && obj.getC4_3IM() != null) {
				eti23.setText(obj.getC4_3IH() + ":" + obj.getC4_3IM());
			}
			if (obj.getC4_3FH() != null && obj.getC4_3FM() != null) {
				ett23.setText(obj.getC4_3FH() + ":" + obj.getC4_3FM());
			}
			et24.setText(obj.getC4_OB());

			if (obj.getC5_1A() != null) {
				sp31.setSelection(Integer.parseInt(obj.getC5_1A()));
			}
			if (obj.getC5_2A() != null) {
				sp32.setSelection(Integer.parseInt(obj.getC5_2A()));
			}
			et33.setText(obj.getC5_3M() + "");
			if (obj.getC5_3IH() != null && obj.getC5_3IM() != null) {
				eti33.setText(obj.getC5_3IH() + ":" + obj.getC5_3IM());
			}
			if (obj.getC5_3FH() != null && obj.getC5_3FM() != null) {
				ett33.setText(obj.getC5_3FH() + ":" + obj.getC5_3FM());
			}
			et34.setText(obj.getC5_OB());

			if (obj.getC6_1A() != null) {
				sp41.setSelection(Integer.parseInt(obj.getC6_1A()));
			}
			if (obj.getC6_2A() != null) {
				sp42.setSelection(Integer.parseInt(obj.getC6_2A()));
			}
			et43.setText(obj.getC6_3M() + "");
			if (obj.getC6_3IH() != null && obj.getC6_3IM() != null) {
				eti43.setText(obj.getC6_3IH() + ":" + obj.getC6_3IM());
			}
			if (obj.getC6_3FH() != null && obj.getC6_3FM() != null) {
				ett43.setText(obj.getC6_3FH() + ":" + obj.getC6_3FM());
			}
			et44.setText(obj.getC6_OB());

			if (obj.getC7_1A() != null) {
				sp51.setSelection(Integer.parseInt(obj.getC7_1A()));
			}
			if (obj.getC7_2A() != null) {
				sp52.setSelection(Integer.parseInt(obj.getC7_2A()));
			}
			et53.setText(obj.getC7_3M() + "");
			if (obj.getC7_3IH() != null && obj.getC7_3IM() != null) {
				eti53.setText(obj.getC7_3IH() + ":" + obj.getC7_3IM());
			}
			if (obj.getC7_3FH() != null && obj.getC7_3FM() != null) {
				ett53.setText(obj.getC7_3FH() + ":" + obj.getC7_3FM());
			}
			et54.setText(obj.getC7_OB());

			if (obj.getC7_21A() != null) {
				sp61.setSelection(Integer.parseInt(obj.getC7_21A()));
			}
			if (obj.getC7_22A() != null) {
				sp62.setSelection(Integer.parseInt(obj.getC7_22A()));
			}
			et63.setText(obj.getC7_23M() + "");
			if (obj.getC7_23IH() != null && obj.getC7_23IM() != null) {
				eti63.setText(obj.getC7_23IH() + ":" + obj.getC7_23IM());
			}
			if (obj.getC7_23FH() != null && obj.getC7_23FM() != null) {
				ett63.setText(obj.getC7_23FH() + ":" + obj.getC7_23FM());
			}
			et64.setText(obj.getC7_2OB());

			if (obj.getC7_31A() != null) {
				sp71.setSelection(Integer.parseInt(obj.getC7_31A()));
			}
			if (obj.getC7_32A() != null) {
				sp72.setSelection(Integer.parseInt(obj.getC7_32A()));
			}
			et73.setText(obj.getC7_33M() + "");
			if (obj.getC7_33IH() != null && obj.getC7_33IM() != null) {
				eti73.setText(obj.getC7_33IH() + ":" + obj.getC7_33IM());
			}
			if (obj.getC7_33FH() != null && obj.getC7_33FM() != null) {
				ett73.setText(obj.getC7_33FH() + ":" + obj.getC7_33FM());
			}
			et74.setText(obj.getC7_3OB());

			if (obj.getC8_1A() != null) {
				sp81.setSelection(Integer.parseInt(obj.getC8_1A()));
			}
			if (obj.getC8_2A() != null) {
				sp82.setSelection(Integer.parseInt(obj.getC8_2A()));
			}
			et83.setText(obj.getC8_3M() + "");
			if (obj.getC8_3IH() != null && obj.getC8_3IM() != null) {
				eti83.setText(obj.getC8_3IH() + ":" + obj.getC8_3IM());
			}
			if (obj.getC8_3FH() != null && obj.getC8_3FM() != null) {
				ett83.setText(obj.getC8_3FH() + ":" + obj.getC8_3FM());
			}
			et84.setText(obj.getC8_OB());

			if (obj.getC9_1A() != null) {
				sp91.setSelection(Integer.parseInt(obj.getC9_1A()));
			}
			if (obj.getC9_2A() != null) {
				sp92.setSelection(Integer.parseInt(obj.getC9_2A()));
			}
			et93.setText(obj.getC9_3M() + "");
			if (obj.getC9_3IH() != null && obj.getC9_3IM() != null) {
				eti93.setText(obj.getC9_3IH() + ":" + obj.getC9_3IM());
			}
			if (obj.getC9_3FH() != null && obj.getC9_3FM() != null) {
				ett93.setText(obj.getC9_3FH() + ":" + obj.getC9_3FM());
			}
			et94.setText(obj.getC9_OB());

			if (obj.getC10_1A() != null) {
				sp101.setSelection(Integer.parseInt(obj.getC10_1A()));
			}
			if (obj.getC10_2A() != null) {
				sp102.setSelection(Integer.parseInt(obj.getC10_2A()));
			}
			et103.setText(obj.getC10_3M() + "");
			if (obj.getC10_3IH() != null && obj.getC10_3IM() != null) {
				eti103.setText(obj.getC10_3IH() + ":" + obj.getC10_3IM());
			}
			if (obj.getC10_3FH() != null && obj.getC10_3FM() != null) {
				ett103.setText(obj.getC10_3FH() + ":" + obj.getC10_3FM());
			}
			et104.setText(obj.getC10_OB());

			if (obj.getC11_1A() != null) {
				sp111.setSelection(Integer.parseInt(obj.getC11_1A()));
			}
			if (obj.getC11_2A() != null) {
				sp112.setSelection(Integer.parseInt(obj.getC11_2A()));
			}
			et113.setText(obj.getC11_3M() + "");
			if (obj.getC11_3IH() != null && obj.getC11_3IM() != null) {
				eti113.setText(obj.getC11_3IH() + ":" + obj.getC11_3IM());
			}
			if (obj.getC11_3FH() != null && obj.getC11_3FM() != null) {
				ett113.setText(obj.getC11_3FH() + ":" + obj.getC11_3FM());
			}
			et114.setText(obj.getC11_OB());
		}
	}

	private void GuardarDatos() {
		obj.setC3_1A(sp11.getSelectedItemPosition() + "");
		obj.setC3_1B(etFuente11.getText().toString());
		obj.setC3_2A(sp12.getSelectedItemPosition() + "");
		obj.setC3_2B(etFuente12.getText().toString());
		obj.setC3_3M(et13.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et13.getText().toString()));
		if (eti13.getText().toString().length() != 0) {
			String[] i1 = eti13.getText().toString().split(":");
			obj.setC3_3IH(i1[0]);
			obj.setC3_3IM(i1[1]);
		} else {
			obj.setC3_3IH(null);
			obj.setC3_3IM(null);
		}
		if (ett13.getText().toString().length() != 0) {
			String[] i1 = ett13.getText().toString().split(":");
			obj.setC3_3FH(i1[0]);
			obj.setC3_3FM(i1[1]);
		} else {
			obj.setC3_3FH(null);
			obj.setC3_3FM(null);
		}
		obj.setC3_OB(et14.getText().toString());

		obj.setC4_1A(sp21.getSelectedItemPosition() + "");
		obj.setC4_2A(sp22.getSelectedItemPosition() + "");
		obj.setC4_3M(et23.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et23.getText().toString()));
		if (eti23.getText().toString().length() != 0) {
			String[] i1 = eti23.getText().toString().split(":");
			obj.setC4_3IH(i1[0]);
			obj.setC4_3IM(i1[1]);
		} else {
			obj.setC4_3IH(null);
			obj.setC4_3IM(null);
		}
		if (ett23.getText().toString().length() != 0) {
			String[] i1 = ett23.getText().toString().split(":");
			obj.setC4_3FH(i1[0]);
			obj.setC4_3FM(i1[1]);
		} else {
			obj.setC4_3FH(null);
			obj.setC4_3FM(null);
		}
		obj.setC4_OB(et24.getText().toString());

		obj.setC5_1A(sp31.getSelectedItemPosition() + "");
		obj.setC5_2A(sp32.getSelectedItemPosition() + "");
		obj.setC5_3M(et33.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et33.getText().toString()));
		if (eti33.getText().toString().length() != 0) {
			String[] i1 = eti33.getText().toString().split(":");
			obj.setC5_3IH(i1[0]);
			obj.setC5_3IM(i1[1]);
		} else {
			obj.setC5_3IH(null);
			obj.setC5_3IM(null);
		}
		if (ett33.getText().toString().length() != 0) {
			String[] i1 = ett33.getText().toString().split(":");
			obj.setC5_3FH(i1[0]);
			obj.setC5_3FM(i1[1]);
		} else {
			obj.setC5_3FH(null);
			obj.setC5_3FM(null);
		}
		obj.setC5_OB(et34.getText().toString());

		obj.setC6_1A(sp41.getSelectedItemPosition() + "");
		obj.setC6_2A(sp42.getSelectedItemPosition() + "");
		obj.setC6_3M(et43.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et43.getText().toString()));
		if (eti43.getText().toString().length() != 0) {
			String[] i1 = eti43.getText().toString().split(":");
			obj.setC6_3IH(i1[0]);
			obj.setC6_3IM(i1[1]);
		} else {
			obj.setC6_3IH(null);
			obj.setC6_3IM(null);
		}
		if (ett43.getText().toString().length() != 0) {
			String[] i1 = ett43.getText().toString().split(":");
			obj.setC6_3FH(i1[0]);
			obj.setC6_3FM(i1[1]);
		} else {
			obj.setC6_3FH(null);
			obj.setC6_3FM(null);
		}
		obj.setC6_OB(et44.getText().toString());

		obj.setC7_1A(sp51.getSelectedItemPosition() + "");
		obj.setC7_2A(sp52.getSelectedItemPosition() + "");
		obj.setC7_3M(et53.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et53.getText().toString()));
		if (eti53.getText().toString().length() != 0) {
			String[] i1 = eti53.getText().toString().split(":");
			obj.setC7_3IH(i1[0]);
			obj.setC7_3IM(i1[1]);
		} else {
			obj.setC7_3IH(null);
			obj.setC7_3IM(null);
		}
		if (ett53.getText().toString().length() != 0) {
			String[] i1 = ett53.getText().toString().split(":");
			obj.setC7_3FH(i1[0]);
			obj.setC7_3FM(i1[1]);
		} else {
			obj.setC7_3FH(null);
			obj.setC7_3FM(null);
		}
		obj.setC7_OB(et54.getText().toString());

		obj.setC7_21A(sp61.getSelectedItemPosition() + "");
		obj.setC7_22A(sp62.getSelectedItemPosition() + "");
		obj.setC7_23M(et63.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et63.getText().toString()));
		if (eti63.getText().toString().length() != 0) {
			String[] i1 = eti63.getText().toString().split(":");
			obj.setC7_23IH(i1[0]);
			obj.setC7_23IM(i1[1]);
		} else {
			obj.setC7_23IH(null);
			obj.setC7_23IM(null);
		}
		if (ett63.getText().toString().length() != 0) {
			String[] i1 = ett63.getText().toString().split(":");
			obj.setC7_23FH(i1[0]);
			obj.setC7_23FM(i1[1]);
		} else {
			obj.setC7_23FH(null);
			obj.setC7_23FM(null);
		}
		obj.setC7_2OB(et64.getText().toString());

		obj.setC7_31A(sp71.getSelectedItemPosition() + "");
		obj.setC7_32A(sp72.getSelectedItemPosition() + "");
		obj.setC7_33M(et73.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et73.getText().toString()));
		if (eti73.getText().toString().length() != 0) {
			String[] i1 = eti73.getText().toString().split(":");
			obj.setC7_33IH(i1[0]);
			obj.setC7_33IM(i1[1]);
		} else {
			obj.setC7_33IH(null);
			obj.setC7_33IM(null);
		}
		if (ett73.getText().toString().length() != 0) {
			String[] i1 = ett73.getText().toString().split(":");
			obj.setC7_33FH(i1[0]);
			obj.setC7_33FM(i1[1]);
		} else {
			obj.setC7_33FH(null);
			obj.setC7_33FM(null);
		}
		obj.setC7_3OB(et74.getText().toString());

		obj.setC8_1A(sp81.getSelectedItemPosition() + "");
		obj.setC8_2A(sp82.getSelectedItemPosition() + "");
		obj.setC8_3M(et83.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et83.getText().toString()));
		if (eti83.getText().toString().length() != 0) {
			String[] i1 = eti83.getText().toString().split(":");
			obj.setC8_3IH(i1[0]);
			obj.setC8_3IM(i1[1]);
		} else {
			obj.setC8_3IH(null);
			obj.setC8_3IM(null);
		}
		if (ett83.getText().toString().length() != 0) {
			String[] i1 = ett83.getText().toString().split(":");
			obj.setC8_3FH(i1[0]);
			obj.setC8_3FM(i1[1]);
		} else {
			obj.setC8_3FH(null);
			obj.setC8_3FM(null);
		}
		obj.setC8_OB(et84.getText().toString());

		obj.setC9_1A(sp91.getSelectedItemPosition() + "");
		obj.setC9_2A(sp92.getSelectedItemPosition() + "");
		obj.setC9_3M(et93.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et93.getText().toString()));
		if (eti93.getText().toString().length() != 0) {
			String[] i1 = eti93.getText().toString().split(":");
			obj.setC9_3IH(i1[0]);
			obj.setC9_3IM(i1[1]);
		} else {
			obj.setC9_3IH(null);
			obj.setC9_3IM(null);
		}
		if (ett93.getText().toString().length() != 0) {
			String[] i1 = ett93.getText().toString().split(":");
			obj.setC9_3FH(i1[0]);
			obj.setC9_3FM(i1[1]);
		} else {
			obj.setC9_3FH(null);
			obj.setC9_3FM(null);
		}
		obj.setC9_OB(et94.getText().toString());

		obj.setC10_1A(sp101.getSelectedItemPosition() + "");
		obj.setC10_2A(sp102.getSelectedItemPosition() + "");
		obj.setC10_3M(et103.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et103.getText().toString()));
		if (eti103.getText().toString().length() != 0) {
			String[] i1 = eti103.getText().toString().split(":");
			obj.setC10_3IH(i1[0]);
			obj.setC10_3IM(i1[1]);
		} else {
			obj.setC10_3IH(null);
			obj.setC10_3IM(null);
		}
		if (ett103.getText().toString().length() != 0) {
			String[] i1 = ett103.getText().toString().split(":");
			obj.setC10_3FH(i1[0]);
			obj.setC10_3FM(i1[1]);
		} else {
			obj.setC10_3FH(null);
			obj.setC10_3FM(null);
		}
		obj.setC10_OB(et104.getText().toString());

		obj.setC11_1A(sp111.getSelectedItemPosition() + "");
		obj.setC11_2A(sp112.getSelectedItemPosition() + "");
		obj.setC11_3M(et113.getText().toString().length() == 0 ? 0 : Integer
				.parseInt(et113.getText().toString()));
		if (eti113.getText().toString().length() != 0) {
			String[] i1 = eti113.getText().toString().split(":");
			obj.setC11_3IH(i1[0]);
			obj.setC11_3IM(i1[1]);
		} else {
			obj.setC11_3IH(null);
			obj.setC11_3IM(null);
		}
		if (ett113.getText().toString().length() != 0) {
			String[] i1 = ett113.getText().toString().split(":");
			obj.setC11_3FH(i1[0]);
			obj.setC11_3FM(i1[1]);
		} else {
			obj.setC11_3FH(null);
			obj.setC11_3FM(null);
		}
		obj.setC11_OB(et114.getText().toString());

		if (con.RespuestaCensoModificar(obj) > 0) {

			Intent ir_evaluacion_iii = new Intent(this,
					Evaluacion_III_Activity.class);
			Bundle datos = getIntent().getExtras();
			datos.putInt("respuesta_id", obj.getRespuesta_id());
			ir_evaluacion_iii.putExtras(datos);
			startActivity(ir_evaluacion_iii);

			Toast.makeText(this, "Se actualizo con exito", Toast.LENGTH_SHORT)
					.show();

			finish();
		} else {
			Toast.makeText(this, "Error al actualizar", Toast.LENGTH_SHORT)
					.show();
		}
	}

	private void AbrirTime(String h, final EditText et, final int sw,
			final String h1) {

		final Calendar c = Calendar.getInstance();
		int horas = c.get(Calendar.HOUR_OF_DAY);
		int minutos = c.get(Calendar.MINUTE);
		if (h.length() != 0) {
			String valores[] = h.split(":");
			horas = Integer.parseInt(valores[0]);
			minutos = Integer.parseInt(valores[1]);
		}

		TimePickerDialog hora = new TimePickerDialog(this,
				new OnTimeSetListener() {

					@Override
					public void onTimeSet(TimePicker view, int hourOfDay,
							int minute) {
						c.set(Calendar.HOUR_OF_DAY, hourOfDay);
						c.set(Calendar.MINUTE, minute);
						SimpleDateFormat sdf = new SimpleDateFormat("HH:mm",
								Locale.US);
						et.setText(sdf.format(c.getTime()));
					}
				}, horas, minutos, true);

		hora.setButton(DatePickerDialog.BUTTON_NEUTRAL, "Borrar",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface arg0, int arg1) {
						et.setText("");
					}
				});
		hora.show();
	}

	private void MostrarFuente(Spinner spTemp, EditText etTemp, String texto) {
		switch (spTemp.getSelectedItemPosition()) {
		case 0:
			etTemp.setEnabled(false);
			etTemp.setText("");
			break;

		case 5:
			etTemp.setEnabled(true);
			if (texto == null || texto.length() != 0) {
				etTemp.setText(texto);
			} else {
				etTemp.setText("");
			}
			break;

		default:
			etTemp.setEnabled(false);
			etTemp.setText(spTemp.getItemAtPosition(
					spTemp.getSelectedItemPosition()).toString());
			break;
		}
	}

	private void MostrarAcciones(Spinner spTemp, EditText etTemp, String texto) {
		switch (spTemp.getSelectedItemPosition()) {
		case 0:
			etTemp.setEnabled(false);
			etTemp.setText("");
			break;
		case 4:
			etTemp.setEnabled(true);
			if (texto == null || texto.length() != 0) {
				etTemp.setText(texto);
			} else {
				etTemp.setText("");
			}
			break;

		default:
			etTemp.setEnabled(false);
			etTemp.setText(spTemp.getItemAtPosition(
					spTemp.getSelectedItemPosition()).toString());
			break;
		}
	}
}
